using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAL;
using BLL;
using DTO;

namespace WellmeadowsHospital
{
    public partial class frmSearchInPatients : DevExpress.XtraEditors.XtraUserControl
    {
        AppointmentBLL appointmentBLL = new AppointmentBLL();
        WardBLL wardBLL = new WardBLL();
        PatientBLL patientBLL = new PatientBLL();
        ListWaitBLL listwaitBLL = new ListWaitBLL();
        BedsBLL bedsBLL = new BedsBLL();
        InPatientsBLL inpatientsBLL = new InPatientsBLL();
        public frmSearchInPatients()
        {
            InitializeComponent();
            gcPatient.DataSource = inpatientsBLL.SearchwithName("");
        }

        private void textEdit78_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                gcPatient.DataSource = inpatientsBLL.SearchwithName(textEdit78.Text);
            }
            catch (Exception ee)
            {
                MessageBox.Show("error: "+ee.Message);
            }
        }

        private void gridView10_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                string wardid = gridView10.GetRowCellValue(gridView10.GetSelectedRows()[0], gcolWardID).ToString();
                gcWard.DataSource = wardBLL.Get_Info_Ward(wardid);
                string listid = gridView10.GetRowCellValue(gridView10.GetSelectedRows()[0], gcolListWaitID).ToString();
                InPatient moi = inpatientsBLL.Get(listid);
                txtWaitListID.Text = moi.ListID;
                txtBednumber.Text = moi.BedNumber;
                txtExpectedstay.Enabled = false;
                dateplace.Enabled = false;
                dateleave.Enabled = false;
                txtWaitListID.Enabled = false;
                simpleButton22.Enabled = true;
            }
            catch (Exception ee)
            {
                MessageBox.Show("error: " + ee.Message);
            }
        }

        private void simpleButton22_Click(object sender, EventArgs e)
        {
            try
            {
                InPatientsDTO nhap = new InPatientsDTO();
                nhap.ListID = txtWaitListID.Text;
                nhap.BedNumber = txtBednumber.Text;
                nhap.ActualLeave = dateActualleave.DateTime;
                if (inpatientsBLL.Update(nhap).Equals("success"))
                {
                    MessageBox.Show("Update success");
                    txtExpectedstay.Enabled = true;
                    dateplace.Enabled = true;
                    dateleave.Enabled = true;
                    txtWaitListID.Enabled = true;
                    simpleButton22.Enabled = false;
                    inpatientsBLL.Update_patient_out();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("error: " + ee.Message);
            }
        }
    }
}
